﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_Flow_GetBangdingPosition_V2]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_Flow_GetBangdingPosition_V2];
GO
CREATE PROCEDURE [dbo].[sproc_Flow_GetBangdingPosition_V2]
    @FlowID int,
    @StepID int
AS
BEGIN
SET NOCOUNT ON

SELECT
        p.position_id,
        p.position_name,
        ISNULL
        (
            (
                SELECT TOP (1) 1
                FROM dbo.uds_flow_member_bind m
                WHERE
                    m.obj_id = p.position_id
                    and m.obj_type = /* position */ 1
                    and m.flow_id = @FlowID
                    and m.step_id = @StepID
            ), 0
        ) as Bound
    FROM
        uds_position p;

END
GO